package com.zgw.his.emr.widget;

import java.util.List;

import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

import com.zgw.his.emr.model.PageRecord;

/**
 * 记录页
 */
public class MedicalPage extends MedicalWidget implements IPage {
	private Composite templateView; // 模板面版
	private PageRecord record;
	private MedicalTemplate template; // 模板控件
	private TemplateRegion region;

	public void initialize(PageRecord record) {
		this.record = record;
	}

	public Control createControl(Composite parent) {
		try {
			if (record.getTemplate() != null) { // 构建页面静态模板
				template = new MedicalTemplate(record.getTemplate());
				templateView = template.createControl(parent);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return templateView;
	}

	// 刷新记录
	public PageRecord refresh_record() {
		if (template != null)
			template.refresh_record();
		return record;
	}

	// 刷新控件
	public void refresh_control() {

	}

	public PageRecord getRecord() {
		return record;
	}

	@Override
	public void setActivate(boolean activate) {
		// TODO Auto-generated method stub

	}

	public void dispose() {
		if (templateView != null && !templateView.isDisposed())
			templateView.dispose();
	}

	/**
	 * 页面排序号
	 * */
	public int getPageIndex() {
		return record.getPageNumber();
	}

	public void setPageIndex(int index) {
		// TODO Auto-generated method stub

	}

	/**
	 * 获得该页面下的控件(根控件)
	 * */
	public Control getControl() {
		return templateView;
	}

	public String getName() {
		String file = record.getTemplate().getTemplateUrl().getFile();
		return file.substring(file.lastIndexOf("/") + 1,
				file.lastIndexOf(".xwt"));
	}

	public Image getImage() {
		// TODO 获得页面图象
		return null;
	}

	public MedicalTemplate getTemplate() {
		return template;
	}

	public static void getCompositeAllControls(Composite com, List<Control> list) {
		if (com == null || com.isDisposed() || list == null)
			return;
		list.add(com);
		for (Control c : com.getChildren()) {
			if (c instanceof Composite) {
				getCompositeAllControls((Composite) c, list);
			} else {
				list.add(c);
			}
		}
	}
}
